package com.campus.controller.normal;

import com.campus.pojo.vo.ClassVO;
import com.campus.pojo.vo.FacultyVO;
import com.campus.pojo.vo.MajorVO;
import com.campus.result.Result;
import com.campus.service.ClassService;
import com.campus.service.FacultyService;
import com.campus.service.MajorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "通用类", description = "院系，宿舍")
@RestController
@RequestMapping
@RequiredArgsConstructor
@CrossOrigin
public class CommonController {
    // 院系相关服务
    private final FacultyService facultyService;
    // 专业相关服务
    private final MajorService majorService;
    // 班级相关服务
    private final ClassService classService;

    /**
     * 查询院系
     * @return
     */
    @GetMapping("/faculty")
    @Operation(summary = "院系名称查询")
    public Result getFaculty(){
        log.info("院系名称查询");
        List<FacultyVO> facultyVOS = facultyService.getFaculty();
        return Result.success(facultyVOS);
    }

    /**
     * 专业查询
     * @param id
     * @return
     */
    @GetMapping("/faculty/major")
    @Operation(summary = "通过院系id查询专业")
    public Result getMajorByFacultyId(@RequestParam(name = "id") Integer id){
        log.info("通过院系id={}查询专业", id);
        List<MajorVO> majorVOS = majorService.getMajorByFacultyId(id);
        return Result.success(majorVOS);
    }

    /**
     * 通过专业id查询班级信息
     * @param id
     * @return
     */
    @GetMapping("/major/class")
    public Result getClassByMajorId(@RequestParam(name = "id") Integer id){
        log.info("通过专业id={}查询班级信息", id);
        List<ClassVO> classVOS = classService.getClassByMajorId(id);
        return Result.success(classVOS);
    }

    /**
     * 查询所有专业
     * @return
     */
    @GetMapping("/major/all")
    @Operation(summary = "专业查询all")
    public Result getMajorAll() {
        log.info("专业查询");
        List<MajorVO> majorVOS = majorService.getMajorAll();
        return Result.success(majorVOS);
    }
}
